#include "slepbase.h"
#include "cslep.h"

void testRunMCLogisticR(){
	int i;
	OPTS opts;
	slep_matrix *A, *Y;
	slep_vector *funVal, *LValue, *c_v;
	slep_matrix* X;
	double rho;
	stopWatch timer;

	A = slepAllocDenseMatrix(100,100);
	X = slepAllocDenseMatrix(100,10);
	Y = slepAllocDenseMatrix(100,10);
	c_v = slepAllocDenseVector(10);
	funVal = slepAllocDenseVector(100);
	LValue = slepAllocDenseVector(100);

	slep_randn(A->data.mtrx,100*100,0.,1.);
	slep_randn(Y->data.mtrx,100*10,0.,1.);
	for(i=0; i < Y->m * Y->n; ++i)
		Y->data.mtrx[i] = (Y->data.mtrx[i]>0)? 1.0 : -1.0;

	opts.lFlag=0;
	opts.mFlag=0;
	opts.nFlag=0;
	opts.rFlag=1;

	opts.rsL2=0;
	opts.maxIter=100;

	slepWriteDenseMatrix("A-mclogr.slm",A);
	slepWriteDenseMatrix("Y-mclogr.slm",Y);
	opts.init = 2;
	opts.tFlag=5;
	opts.maxIter = 100;
	opts.q = 2;
	opts.REGISTER = SlepOPT_maxIter | SlepOPT_rsL2 | SlepOPT_q;

	opts.rsL2 = 0.0;
	opts.rFlag = 1;
	rho=0.4;

	opts.mFlag=0;
	opts.lFlag=0;
	startTimer(&timer);
	mcLogisticR(A,Y,rho,&opts,X,c_v,funVal,LValue);
	stopTimer(&timer);
	printf("Time taken = %lf\n", getElapsedTime(&timer));
	slepWriteDenseMatrix("x-mclogr-1.slm",X);
	slepVerboseWriteDenseVector("f-mclogr-1.slv",funVal);
	slepVerboseWriteDenseVector("L-mclogr-1.slv",LValue);

	opts.mFlag=1;
	startTimer(&timer);
	mcLogisticR(A,Y,rho,&opts,X,c_v,funVal,LValue);
	stopTimer(&timer);
	printf("Time taken = %lf\n", getElapsedTime(&timer));
	slepWriteDenseMatrix("x-mclogr-2.slm",X);
	slepVerboseWriteDenseVector("f-mclogr-2.slv",funVal);
	slepVerboseWriteDenseVector("L-mclogr-2.slv",LValue);

	opts.lFlag=1;
	opts.mFlag=1;
	startTimer(&timer);
	mcLogisticR(A,Y,rho,&opts,X,c_v,funVal,LValue);
	stopTimer(&timer);
	printf("Time taken = %lf\n", getElapsedTime(&timer));
	slepWriteDenseMatrix("x-mclogr-3.slm",X);
	slepVerboseWriteDenseVector("f-mclogr-3.slv",funVal);
	slepVerboseWriteDenseVector("L-mclogr-3.slv",LValue);
}